import { createElement } from './createElement'
import { patchVnode } from './patchVNode'
import { vnode } from './vnode'
export function patch(oldVNode, newVNode) {
    if (!oldVNode.hasOwnProperty('sel')) {
        // 如果老节点不是虚拟节点，创建虚拟节点
        oldVNode = vnode(oldVNode.tagName.toLowerCase(), {}, [], undefined, oldVNode)
    }
    if (oldVNode.sel === newVNode.sel && oldVNode.key === newVNode.key) {
        // 进一步比较
        patchVnode(oldVNode, newVNode)
    } else {
        // 创建节点，在老节点之前插入，输出老节点
        let dom = createElement(newVNode)
        const oldDom = oldVNode.elm
        oldDom.parentNode.insertBefore(dom, oldDom)
        oldDom.parentNode.removeChild(oldVNode.elm)
    }
}